/*
 * @Author: asushiye
 * @Date: 2020-07-14 10:48:58
 * @Commit: file content
 */
import { Component, inject, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AfMessageService } from '@core';
import { STColumn, STComponent } from '@delon/abc/st';
import { SFSchema } from '@delon/form';
import { _HttpClient } from '@delon/theme';
import { SharedModule } from '@shared';

import { AfSystemService } from '../../af-system.service';

@Component({
  selector: 'app-schedule-log',
  standalone: true,
  imports: [SharedModule],
  templateUrl: './schedule-log.component.html'
})
export class ScheduleLogComponent implements OnInit {
  req: any = { lazyLoad: true };
  queryParams: any = { code: '' };
  url = '';
  searchSchema: SFSchema;

  @ViewChild('st', { static: false }) st!: STComponent;

  columns: STColumn[] = [
    { title: '作业编码', index: 'code', width: '150px', sort: true },
    { title: '作业名称', index: 'name', width: '180px', sort: true },
    // { title: '调用表达式', index: 'cron', width: '100px' },

    // { title: '下次运行时间', index: 'scheduledNextTime', width: '200px' },
    // { title: '作业日志', index: 'scheduledInfo' },
    {
      title: '运行状态',
      index: 'jobStatus',
      type: 'badge',
      width: '90px',
      badge: {
        pending: { text: '已完成', color: 'success' },
        processing: { text: '执行中', color: 'processing' },
        failed: { text: '执行失败', color: 'error' }
      }
    },
    { title: '运行开始时间', index: 'jobStartTime', width: '220px' },
    {
      title: '运行结束时间',
      index: 'jobEndTime',
      width: '220px'
    },
    { title: '消耗毫秒', index: 'jobCost', type: 'number', width: '125px' },
    { title: '运行结果', index: 'jobResult', width: '375px' },

    // { title: '执行类型', index: 'executeType', width: '75px' },
    // { title: '执行程序', index: 'executeName', width: '175px' },
    // { title: '执行方法', index: 'executeMethod', width: '120px' },
    // { title: '请求参数', index: 'executeParam', width: '120px' },

    // { title: '线程数', index: 'numberOfThread', width: '75px' },
    // { title: '数据条数', index: 'numberOfData', width: '75px' },

    // {
    //   title: '启动类型',
    //   index: 'startupType',
    //   type: 'badge',
    //   width: '90px',
    //   badge: {
    //     auto: { text: '自启动', color: 'success' },
    //     manual: { text: '手工启动', color: 'warning' },
    //     disable: { text: '已禁用', color: 'default' }
    //   }
    // },

    // { title: '备注', index: 'remark' },
    // { title: '作业分组', index: 'groupCode', width: '100px' },

    { title: '总运行数', index: 'totalCount', type: 'number', width: '75px' },
    { title: '总消耗毫秒', index: 'totalCost', type: 'number', width: '95px' },
    { title: '总失败数', index: 'failedCount', type: 'number', width: '75px' }
    // {
    //   title: '作业状态',
    //   index: 'scheduledStatus',
    //   width: '80px',
    //   fixed: 'right',
    //   className: 'text-center',
    //   type: 'tag',
    //   tag: {
    //     started: { text: '已启动', color: 'success' },
    //     stopped: { text: '已停止', color: 'orange' },
    //     disabled: { text: '已禁用', color: 'cyan' },
    //     failed: { text: '失败', color: 'red' }
    //   }
    // }
  ];
  private readonly sysSrv = inject(AfSystemService);
  constructor(private route: ActivatedRoute) {
    const params = this.route.snapshot.queryParams;
    this.queryParams.code = params['code'];
    console.log(this.queryParams);

    this.searchSchema = {
      properties: {
        code: {
          type: 'string',
          title: '作业编号',
          default: this.queryParams.code
        }
      }
    };
    this.req = { params: this.queryParams, lazyLoad: false };
  }

  ngOnInit() {
    this.url = this.sysSrv.getScheduleJobLogUrl();
    // this.st.reset(this.queryParams);
  }
}
